package com.jk.dao;

import com.jk.pojo.PayBank;
import com.jk.pojo.PayLog;
import com.jk.pojo.PayUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * dao层 余额 一系列操作数据库
 */
public interface WalletMapper {
    /**查询用户所有信息  包括用户余额 李亚峰*/
    @Select(" select * from pay_user where userAccount = #{useraccount} ")
    PayUser queryUserBalance(String useraccount);

    /**充值修改用户余额 李亚峰*/
    @Update(" update pay_user set userBalance = userBalance+#{money} where userAccount = #{useraccount} ")
    int rechargeToUserBalanc(@Param("money") Double money,@Param("useraccount")String useraccount);

    /**充值完修改银行卡余额 李亚峰*/
    @Update(" update pay_bank set bankMoney = bankMoney - #{money} where bankNum = #{bankNum}")
    int rechargeToBankMoney(@Param("money")Double money,@Param("bankNum")String bankNum,@Param("useraccount")String useraccount);

    /**查询银行账户余额 前台判断是否充足 李亚峰*/
    @Select(" select bankMoney from pay_bank where bankNum = #{bankNum} ")
    PayBank queryBankMoney(String bankNum);


    /**转账到别人支付宝 别人支付宝金额增加  李亚峰*/
    @Update(" update pay_user set userBalance = userBalance+#{Money} where userAccount = #{userNumber} ")
    int transferToUserBalanc(@Param("Money")Double Money,@Param("userNumber")String userNumber);

    /**转账到别人支付宝  自己支付宝账号减少余额*/
    @Update(" update pay_user set userBalance = userBalance-#{Money} where userAccount = #{useraccount} ")
    int transferToReduceUserBalanc(@Param("Money")Double Money,@Param("useraccount")String useraccount);

    /**转账到银行卡 银行卡余额增加 李亚峰*/
    @Update(" update pay_bank set bankMoney = bankMoney + #{money} where bankNum = #{bankNum}")
    int transferToBankManey(@Param("money") Double money,@Param("bankNum") String bankNum);

    /**转账到银行卡  账号余额减少 李亚峰*/
    @Update(" update pay_user set userBalance = userBalance-#{money} where userAccount = #{useraccount} ")
    int transferReduceToUserBalanc(@Param("money") Double money ,@Param("useraccount") String useraccount);

    /**验证银行密码是否成功*/
    @Select(" select * from pay_bank where bankNum=#{bankNum} and bankPwd=#{bankPwd} ")
    PayBank QueruBankPwd(@Param("bankNum")String bankNum,@Param("bankPwd")String bankPwd);

    /**账户验证密码是否正确*/
    @Select(" select * from pay_user where userAccount =#{useraccount} and paymentPwd=#{paymentPwd} ")
    PayUser QueruUserPaymentPwd(@Param("useraccount") String useraccount,@Param("paymentPwd") String paymentPwd);

    @Insert(" insert into pay_log(logId,logType,logInfo,saveTime,dealAmont,logSuccess,runNumber,userId,operatorId , logStatus )"+
            " values ( #{logId},#{logType},#{logInfo},#{saveTime},#{dealAmont},#{logSuccess},#{runNumber},"+
            " #{userId},#{operatorId},#{logStatus} ) ")
    void rechargeAddLog(PayLog log);

    /**根据用户ID 回显银行卡号*/
   @Select(" select bankNum from pay_bank where userId = #{userid} ")
    String selectBankNum(String userid);
}
